/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import bus.DanhMucBUS;
import bus.DanhMucConBUS;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import pojo.Danhmuc;
import pojo.Danhmuccon;
import pojo.Laptop;

/** 
 *
 * @author Jackhit
 */
public class trangchuController extends SimpleFormController {

    public trangchuController() {
//        Initialize controller properties here or
//        in the Web Application Context

        setCommandClass(Danhmuc.class);
        setCommandName("MyCommandName");
        setSuccessView("successView");
        setFormView("Trangchu");
    }
    
   private DanhMucConBUS danhmucconBUS;
   private DanhMucBUS   danhmucBUS;
    @Override
    protected ModelAndView onSubmit(
            HttpServletRequest request, 
            HttpServletResponse response, 
            Object command, 
            BindException errors) throws Exception {
        ModelAndView mv = new ModelAndView(getSuccessView());
        //Do something...
        return mv;
    }

    @Override
    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
        ModelAndView mv = super.showForm(request, response, errors);
        List<Danhmuccon> danhMucLaptop = danhmucconBUS.layDanhSachDanhMucConTheoId(1);
        List<Danhmuccon> danhMucDesktop = danhmucconBUS.layDanhSachDanhMucConTheoId(2);
        List<Danhmuccon> danhMucLCD = danhmucconBUS.layDanhSachDanhMucConTheoId(3);
        List<Danhmuccon> danhMucPhone = danhmucconBUS.layDanhSachDanhMucConTheoId(4);
        List<Danhmuccon> danhMucServer = danhmucconBUS.layDanhSachDanhMucConTheoId(6);

        List<Danhmuc> danhmuc = danhmucBUS.layDanhSachDanhMuc();

        mv.addObject("dmLaptops", danhMucLaptop);
        mv.addObject("dmDesktops", danhMucDesktop);
        mv.addObject("dmLcds", danhMucLCD);
        mv.addObject("dmPhones", danhMucPhone);
        mv.addObject("dmServers", danhMucServer);
        mv.addObject("dms", danhmuc);
        return mv;
    }

    public void setDanhmucBUS(DanhMucBUS danhmucBUS) {
        this.danhmucBUS = danhmucBUS;
    }

    public void setDanhmucconBUS(DanhMucConBUS danhmucconBUS) {
        this.danhmucconBUS = danhmucconBUS;
    }

}